xtask\tasks\guest_test\uefi/
mod.rs1use crate::Xtask;
5use clap::Parser;
6use std::path::Path;
7use std::path::PathBuf;
8use xshell::cmd;
9
10mod gpt_efi_disk;
11
12#[derive(Parser)]
14pub struct Uefi {
15 #[clap(long)]
22 output: Option<PathBuf>,
23
24 #[clap(long)]
26 #[expect(clippy::option_option)]
27 bootx64: Option<Option<PathBuf>>,
28
29 #[clap(long)]
31 #[expect(clippy::option_option)]
32 bootaa64: Option<Option<PathBuf>>,
33}
34
35impl Xtask for Uefi {
36 fn run(self, _ctx: crate::XtaskCtx) -> anyhow::Result<()> {
37 let mut files = Vec::new();
38
39 let bootx64 = if self.bootx64.is_none() && self.bootaa64.is_none() {
41 Some(None)
42 } else {
43 self.bootx64
44 };
45
46 if let Some(bootx64) = bootx64.as_ref() {
47 if let Some(bootx64) = bootx64 {
48 files.push((Path::new("efi/boot/bootx64.efi"), bootx64.as_path()));
49 } else {
50 let sh = xshell::Shell::new()?;
51 cmd!(
52 sh,
53 "cargo build -p guest_test_uefi --target x86_64-unknown-uefi"
54 )
55 .run()?;
56
57 files.push((
58 Path::new("efi/boot/bootx64.efi"),
59 Path::new("./target/x86_64-unknown-uefi/debug/guest_test_uefi.efi"),
60 ));
61 }
62 }
63
64 if let Some(bootaa64) = self.bootaa64.as_ref() {
65 if let Some(bootaa64) = bootaa64 {
66 files.push((Path::new("efi/boot/bootaa64.efi"), bootaa64.as_path()))
67 } else {
68 let sh = xshell::Shell::new()?;
69 cmd!(
70 sh,
71 "cargo build -p guest_test_uefi --target aarch64-unknown-uefi"
72 )
73 .run()?;
74
75 files.push((
76 Path::new("efi/boot/bootaa64.efi"),
77 Path::new("./target/aarch64-unknown-uefi/debug/guest_test_uefi.efi"),
78 ));
79 }
80 }
81
82 let out_img = match self.output {
83 Some(path) => path,
84 None => {
85 if files.len() != 1 {
86 anyhow::bail!(
87 "Multiple EFI files specified. Please provide an explicit output path."
88 )
89 }
90 files[0].1.with_extension("img")
91 }
92 };
93
94 gpt_efi_disk::create_gpt_efi_disk(&out_img, &files)?;
95
96 Ok(())
97 }
98}